<?php

namespace App\Service\Auth;

use App\Constants\ErrorCode;
use App\Helpers\FlashLoginUtil;

/**
 * 手机号一键登录
 */
class AuthQuickService extends AuthBaseService
{
    public function handle()
    {
        $platform = $this->request->input('platform', 1);
        $flashToken = $this->request->input('flash_token', '');
        //获取手机号
        $queryResult = FlashLoginUtil::queryMobile($platform, $flashToken, $this->appId);
        if (!isset($queryResult['mobile']) || !$queryResult['mobile']) {
            return $this->setError(ErrorCode::PARAMETER_ERROR, $queryResult['message'] ?: 'Flash token验证错误~');
        }
        $phone = $queryResult['mobile'];
        //手机号登录（注册）
        $ret = $this->authPhoneLogin($phone);
        $ret['show_invitecode'] = env('SHOW_INVITECODE', 1);
        return $ret;
    }
}
